package buildinjava;

import buildinjava.io.FileFilters;
import buildinjava.io.Files;
import buildinjava.io.WildcardFileFilter;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.FileFilter;
import java.net.URL;
import java.util.List;

/**
 * Information about BuildInJava.
 *
 * @author Gili Tzabari
 */
public final class BuildInJava
{
	private final File installationDirectory;

	/**
	 * Creates a new BuildInJava object.
	 *
	 * @param installationDirectory the installation directory
	 * @throws IllegalArgumentException if installationDirectory is not a directory
	 */
	BuildInJava(File installationDirectory)
	{
		this.installationDirectory = installationDirectory;
		if (!installationDirectory.isDirectory())
			throw new IllegalArgumentException(installationDirectory.getAbsoluteFile()
																				 + " is not a directory");
	}

	/**
	 * Returns the installation directory.
	 * 
	 * @return the installation directory
	 */
	public File getInstallationDirectory()
	{
		return installationDirectory;
	}

	/**
	 * Returns the BuildInJava compile classpath.
	 *
	 * @return the BuildInJava compile classpath
	 */
	public List<URL> getClassPath()
	{
		File libraryDirectory = new File(installationDirectory, "netbeans/dist");
		if (!libraryDirectory.isDirectory())
			libraryDirectory = installationDirectory;
		//throw new BuildException(libraryDirectory.getAbsoluteFile() + " is not a directory");
		FileFilter jarFiles = new WildcardFileFilter("*.jar");
		return Lists.transform(Files.list(libraryDirectory, FileFilters.isDirectory(),
			jarFiles), Files.toURL());
	}
}
